<%--
  Created by IntelliJ IDEA.
  User: DELL
  Date: 2020/7/22
  Time: 20:00
  To change this template use File | Settings | File Templates.
--%>
<%--
  Created by IntelliJ IDEA.
  User: 10218
  Date: 2019/06/30
  Time: 11:33
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ page import="com.example.demo.packageModel.Together" %>
<%@ page import="java.util.Collection" %>
<%@ page import="java.util.Iterator" %>

<script src="${ctx}/webjars/jquery/3.3.1-2/jquery.min.js"></script>

<%!

    String INFo  = " ";
    String INFo0 = "1 ";
    String INFo1 = "2 ";
    String INFo2 = "3 ";
    String INFo3 = "4 ";
    String INFo4 = "5 ";
    Together user;
    Iterator<Together> it;
    int page = 5;
    int aa = 3;
    int kkk;
%>

<html>
<head>
    <title>$Title$</title>
    <style>div{ display:inline}</style>
</head>

<body onload="Init()">
<!--
<input id="btnLoad" type="button" value="后->前">
<button onclick="GetInfo()">获取数据0</button>
<button onclick="BACK()">BACK</button>
<button onclick="LIST()">LIST</button>
<button onclick="INP()">INPUT</button>
<button onclick="jump()">JUMP</button>
<button onclick="REVER()">Reverse</button>
<button onclick="AAA0(0)">00</button>
<button onclick="AAA0(1)">11</button>
<button onclick="AAA0(2)">22</button>-->
<button onclick="scan()">插入</button>
<button onclick="del()">删除</button>
<button onclick="update()">更改</button>

<br>
<button onclick="AAA0(-1)">《</button>
<div id="pageING"></div>
<div id="pageAA">  /  </div>
<div id="pageALL"></div>
<button onclick="AAA0(-3)">》</button>
请输入跳转页码:<input type="text" name="jumppages" id="jumppages" value="1">
<button onclick="JumpPage()">跳转</button>
<br>


<table width="800" cellpadding="0"  border = 1>
    <tr>
        <td>号码</td>
        <td>姓名</td>
        <td>工作</td>
        <td>mgr</td>
        <td>hiredate</td>
        <td>sal</td>
        <td>comm</td>
        <td>部门编号</td>
        <td>部门名称</td>
        <td>地址</td>
    </tr>
    <%
        for(int i=0;i<5;i++)
        {
            out.print("<tr>");
            for(int j=0;j<10;j++)
            {
                String name = "bu"+i+j;
                out.print("<td id=\""+name+"\">"+"Null"+"</td>");
            }
            out.print("</tr>");
        }
    %>
</table>


<script>
    document.getElementById("btnLoad").onclick = function () {
        // 1. 创建XMLHttpRequest对象
        alert("BUTTON1 --> START");
        var xmlhttp;
        if (window.XMLHttpRequest) {
            xmlhttp = new XMLHttpRequest();
            alert(xmlhttp);
        } else {
            xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
        }
        console.log(xmlhttp);
        // 2. 发送Ajax请求
        xmlhttp.open("GET", "/test/content", true);
        xmlhttp.send();
        // 3. 处理服务器响应
        alert("BUTTON1 --> FUNC" + xmlhttp.readyState);
        xmlhttp.onreadystatechange = function () {
            alert(xmlhttp.readyState +"<-->"+ xmlhttp.status);
            if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
                var t = xmlhttp.responseText;
                alert("hei--hei");
                document.getElementById("bu00").innerHTML = "+++";
            }
        };
        alert(xmlhttp.responseText);
        alert("BUTTON1 --> END" + xmlhttp.readyState);
    }

    function GetInfo() {
        // 1. 创建XMLHttpRequest对象
        //alert("BUTTON1 --> START");
        var xmlhttp;
        if (window.XMLHttpRequest) {
            xmlhttp = new XMLHttpRequest();
            //alert(xmlhttp);
        } else {
            xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
        }
        console.log(xmlhttp);
        // 2. 发送Ajax请求
        xmlhttp.open("GET", "/test/content", true);
        xmlhttp.send();
        // 3. 处理服务器响应
        //alert("BUTTON1 --> FUNC" + xmlhttp.readyState);
        xmlhttp.onreadystatechange = function () {
            //alert(xmlhttp.readyState +"<-->"+ xmlhttp.status);
            if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
                var t = xmlhttp.responseText;
                //var JsonObjs = eval("(" + t + ")");      //或者：var JsonObjs = $.parseJSON(data);
                //n=JsonObjs.length;
                //alert(JsonObjs);//alert(JsonObjs);---->弹出[object Object],[object Object],
                //alert(n);
                document.getElementById("bu00").innerHTML = "***";
                document.getElementById("bu10").innerHTML = t[0];
            }
        };
        //alert(xmlhttp.responseText);
       // alert("BUTTON1 --> END" + xmlhttp.readyState);
    }

    function BACK() {
        // 1. 创建XMLHttpRequest对象
        var xmlhttp;
        if (window.XMLHttpRequest) {
            xmlhttp = new XMLHttpRequest();
        } else {
            xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
        }
        console.log(xmlhttp);
        // 2. 发送Ajax请求
        xmlhttp.open("GET", "/test/ewer", true);
        xmlhttp.send();
        // 3. 处理服务器响应
        xmlhttp.onreadystatechange = function () {
            if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
                var t = xmlhttp.responseText;
                alert("start     0");
                var list = eval('(' + t + ')');
                alert("start     1");
                $.each(list,function(i, item) {
                    alert("i是" + i + "用户ID" + item.getEname());
                });
                alert("start     2");
            }
        };
    }

    function LIST() {
        // 1. 创建XMLHttpRequest对象
        var xmlhttp;
        if (window.XMLHttpRequest) {
            xmlhttp = new XMLHttpRequest();
        } else {
            xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
        }
        console.log(xmlhttp);
        // 2. 发送Ajax请求
        xmlhttp.open("GET", "/test/que", true);
        xmlhttp.send();
        // 3. 处理服务器响应
        xmlhttp.onreadystatechange = function () {
            if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
                var t = xmlhttp.responseText;

                alert(t);
                var list = eval('(' + t + ')');
                alert(list[0]);
                alert(list[0].dname);

                document.getElementById("bu20").innerHTML = list[0].dname;
                alert("END!!!")

            }
        };
    }

    function INP() {
        // 1. 创建XMLHttpRequest对象
        var xmlhttp;
        if (window.XMLHttpRequest) {
            xmlhttp = new XMLHttpRequest();
        } else {
            xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
        }
        console.log(xmlhttp);
        // 2. 发送Ajax请求
        xmlhttp.open("GET", "/test/INFOA", true);
        xmlhttp.send();
        // 3. 处理服务器响应
        xmlhttp.onreadystatechange = function () {
            if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
                var t = xmlhttp.responseText;

                alert(t);
                var list = eval('(' + t + ')');
                alert(list[0]);
                alert(list[0].dname);
                for (var i = 0; i < 5; i++) {
                    var butt = "bu" + i;
                    var buttt = butt + "0";
                    document.getElementById(buttt).innerHTML = list[i].empno;
                    var buttt = butt + "1";
                    document.getElementById(buttt).innerHTML = list[i].ename;
                    var buttt = butt + "2";
                    document.getElementById(buttt).innerHTML = list[i].job;
                    var buttt = butt + "3";
                    document.getElementById(buttt).innerHTML = list[i].mgr;
                    var buttt = butt + "4";
                    document.getElementById(buttt).innerHTML = list[i].hiredate;
                    var buttt = butt + "5";
                    document.getElementById(buttt).innerHTML = list[i].sal;
                    var buttt = butt + "6";
                    document.getElementById(buttt).innerHTML = list[i].comm;
                    var buttt = butt + "7";
                    document.getElementById(buttt).innerHTML = list[i].deptno;
                    var buttt = butt + "8";
                    document.getElementById(buttt).innerHTML = list[i].dname;
                    var buttt = butt + "9";
                    document.getElementById(buttt).innerHTML = list[i].loc;
                }
                //document.getElementById("bu20").innerHTML = list[0].dname;
                alert("END!!!")
            }
        };
    }

    function Init() {
        //alert("Init alert!!!");
        // 1. 创建XMLHttpRequest对象


        var xmlhttp;
        if (window.XMLHttpRequest) {
            xmlhttp = new XMLHttpRequest();
        } else {
            xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
        }
        console.log(xmlhttp);
        // 2. 发送Ajax请求
        xmlhttp.open("GET", "/test/getPAGES", true);
        xmlhttp.send();
        // 3. 处理服务器响应
        xmlhttp.onreadystatechange = function () {
            if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
                var t = xmlhttp.responseText;
                document.getElementById("pageALL").innerHTML = t;
            }
        };

        AAA0(0);
    }

    //跳转到某个jsp
    function jump() {
        alert("jump");
        window.location.href = "http://localhost:8080/test/4";
    }

    function REVER() {

        // 1. 创建XMLHttpRequest对象
        var xmlhttp;
        if (window.XMLHttpRequest) {
            xmlhttp = new XMLHttpRequest();
        } else {
            xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
        }
        console.log(xmlhttp);
        // 2. 发送Ajax请求
        //*********************************************************************
        alert("send START!!!");
        xmlhttp.open("POST", "/test/trans", false);
        alert("1     1");
        var pp = 1;
        alert("1     "+pp);
        var person = {
            name : '皮皮虾',
            Kind: pp,
        };
        alert("1     2  "+person);
        //var json = JSON.stringify(person);//把person变为json串
        var json = JSON.stringify(pp);
        xmlhttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
        alert("1     3");
        xmlhttp.send(json);
        alert("send OVER!!!");
        //*********************************************************************
        xmlhttp.open("GET", "/test/INFOA", true);
        xmlhttp.send();
        // 3. 处理服务器响应
        xmlhttp.onreadystatechange = function () {
            if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
                var t = xmlhttp.responseText;

                alert(t);
                var list = eval('(' + t + ')');
                alert(list[0]);
                alert(list[0].dname);
                for (var i = 0; i < 5; i++) {
                    var butt = "bu" + i;
                    var buttt = butt + "0";
                    document.getElementById(buttt).innerHTML = list[i].empno;
                    var buttt = butt + "1";
                    document.getElementById(buttt).innerHTML = list[i].ename;
                    var buttt = butt + "2";
                    document.getElementById(buttt).innerHTML = list[i].job;
                    var buttt = butt + "3";
                    document.getElementById(buttt).innerHTML = list[i].mgr;
                    var buttt = butt + "4";
                    document.getElementById(buttt).innerHTML = list[i].hiredate;
                    var buttt = butt + "5";
                    document.getElementById(buttt).innerHTML = list[i].sal;
                    var buttt = butt + "6";
                    document.getElementById(buttt).innerHTML = list[i].comm;
                    var buttt = butt + "7";
                    document.getElementById(buttt).innerHTML = list[i].deptno;
                    var buttt = butt + "8";
                    document.getElementById(buttt).innerHTML = list[i].dname;
                    var buttt = butt + "9";
                    document.getElementById(buttt).innerHTML = list[i].loc;
                }
                //document.getElementById("bu20").innerHTML = list[0].dname;
                alert("END!!!")
            }
        };
    }

    //显示数据
    function AAA0(idd) {
        // 1. 创建XMLHttpRequest对象
        var xmlhttp;
        if (window.XMLHttpRequest) {
            xmlhttp = new XMLHttpRequest();
        } else {
            xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
        }
        console.log(xmlhttp);
        // 2. 发送Ajax请求
        //*********************************************************************
        xmlhttp.open("POST", "/test/trans", false);
        var pp;
        pp = idd;
        //alert("num:"+pp);
        var json = JSON.stringify(pp);
        xmlhttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
        xmlhttp.send(json);

        //*********************************************************************

        getPages();




        restart();
        xmlhttp.open("GET", "/test/INFOA", true);
        xmlhttp.send();
        // 3. 处理服务器响应
        xmlhttp.onreadystatechange = function () {
            if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
                var t = xmlhttp.responseText;

                var list = eval('(' + t + ')');

                for (var i = 0; i < 5; i++) {
                    var butt = "bu" + i;
                    var buttt = butt + "0";
                    document.getElementById(buttt).innerHTML = list[i].empno;
                    var buttt = butt + "1";
                    document.getElementById(buttt).innerHTML = list[i].ename;
                    var buttt = butt + "2";
                    document.getElementById(buttt).innerHTML = list[i].job;
                    var buttt = butt + "3";
                    document.getElementById(buttt).innerHTML = list[i].mgr;
                    var buttt = butt + "4";
                    document.getElementById(buttt).innerHTML = list[i].hiredate;
                    var buttt = butt + "5";
                    document.getElementById(buttt).innerHTML = list[i].sal;
                    var buttt = butt + "6";
                    document.getElementById(buttt).innerHTML = list[i].comm;
                    var buttt = butt + "7";
                    document.getElementById(buttt).innerHTML = list[i].deptno;
                    var buttt = butt + "8";
                    document.getElementById(buttt).innerHTML = list[i].dname;
                    var buttt = butt + "9";
                    document.getElementById(buttt).innerHTML = list[i].loc;
                }
            }
        }
    }

    //获得当前页面编号
    function getPages() {
        // 1. 创建XMLHttpRequest对象
        var xmlhttp;
        if (window.XMLHttpRequest) {
            xmlhttp = new XMLHttpRequest();
        } else {
            xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
        }
        console.log(xmlhttp);
        // 2. 发送Ajax请求
        xmlhttp.open("GET", "/test/getPaging", true);
        xmlhttp.send();
        // 3. 处理服务器响应
        xmlhttp.onreadystatechange = function () {
            if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
                var t = xmlhttp.responseText;
                //alert(t);
                document.getElementById("pageING").innerHTML = t;
            }
        };

    }

    //清空表格
    function restart() {
        for(var i=0; i<5; i++)
        {
            for(var k=0; k<10; k++)
            {
                var butt = "bu"+i+k;
                document.getElementById(butt).innerHTML = "NULL";
            }
        }
    }

    //输入数据
    function scan() {
        alert("insert!!!");
        window.location.href = "http://localhost:8080/test/insert";
    }

    //删除数据
    function del() {
        alert("delete!!!");
        window.location.href = "http://localhost:8080/test/del";
    }

    //更改数据
    function update() {
        alert("update!!!");
        window.location.href = "http://localhost:8080/test/update";
    }

    //function中创建button试验
    function bualert() {
        alert("Is OK!!!");
    }

    //跳转页面
    function JumpPage() {
        var jump_pages=document.getElementById("jumppages");
        var page_count_Str=document.getElementById("pageALL").innerText;
        var page_count_int = parseInt(page_count_Str);
        var re = /^[0-9]*$/;   //判断字符串是否为数字
        if (!re.test(jump_pages.value))
        {
            alert("请输入数字！！！");
            return;
        }
        if(page_count_int < jump_pages.value || jump_pages.value <= 0)
            alert("输入不符规定！！！");
        else {
            alert("成功跳转到："+jump_pages.value);
            AAA0(jump_pages.value-1);
        }

    }
</script>
</body>
</html>
